package summerRepo

import (
	"github.com/jinzhu/gorm"
	"github.com/rs/zerolog/log"
	"webGoDemo/model"
	summerContainer2 "webGoDemo/summer/summerContainer"
)

type UserRepo struct {
	db gorm.DB
}

func InitUserRepo() {
	summerContainer2.Add("UserRepo", UserRepo{
		db: summerContainer2.Get("db").(gorm.DB),
	})
}

func (u *UserRepo) ListUser() ([]*model.User, error) {
	var users []*model.User
	err := u.db.
		Table("user").
		Limit(10).
		Find(&users).Error
	if err != nil {
		return nil, err
	}
	log.Info().Interface("user", users).Send()
	return users, nil
}
